package cn.brilliantfuture.commentry.sms.impl;

import java.util.List;

import javax.ejb.Remove;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import cn.brilliantfuture.commentry.entity.SmsInfo;
import cn.brilliantfuture.commentry.sms.SMSMessageLocal;

/**
 * 
 * Title: Communication Entry
 * 
 * Author:  LiTian  
 *
 * Date: 2012-5-11
 * 
 * Description:
 * 
 */
@Stateless
public class SMSMessageImpl implements SMSMessageLocal {

	@PersistenceContext(unitName = "commentry-jpa")
	EntityManager entityManager;

	@SuppressWarnings("unchecked")
	public String querySMSMessage(Integer language, Integer smsUse, Integer applyOrient) {
		List<SmsInfo> list = entityManager.createQuery("select smsInfo from SmsInfo smsInfo where deleted = 0 and smsInfo.languageInfo.languageInfoId = :languageInfoId and smsInfo.smsUse = :smsUse and smsInfo.applyOrient = :applyOrient").setParameter("languageInfoId", language).setParameter("smsUse", smsUse).setParameter("applyOrient", applyOrient).getResultList();

		if (null != list && list.size() > 0)
			return list.get(0).getSmsContent();
		
		return null;
	}

	@Remove
	public void remove() {
		
	}

}
